<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>让字符串成为回文串的最少插入次数</title>
</head>
<body>
  <script>
    function fn(s) {
      const n = s.length;
      const dp = new Array(n).fill(0);
      let temp = 0;
      for (let i = n - 2; i >= 0; i--) {
        let pre = 0;
        for (let j = i + 1; j < n; j++) {
          temp = dp[j];
          if (s[i] === s[j]) {
            dp[j] = pre;
          } else {
            dp[j] = Math.min(dp[j], dp[j - 1]) + 1;
          }
          pre = temp;
        }
      }
      return dp[n - 1];
    }
    console.log(fn('zzazz'))
  </script>
</body>
</html>